﻿using System.Text.Json.Serialization;

public class WeChatTokenResponse
{
    [JsonPropertyName("access_token")]
    public string AccessToken { get; set; }

    [JsonPropertyName("expires_in")]
    public int ExpiresIn { get; set; }

    [JsonPropertyName("refresh_token")]
    public string RefreshToken { get; set; }

    [JsonPropertyName("openid")]
    public string OpenId { get; set; }

    [JsonPropertyName("scope")]
    public string Scope { get; set; }

    [JsonPropertyName("unionid")]
    public string UnionId { get; set; }

    [JsonPropertyName("errcode")]
    public string ErrorCode { get; set; }

    [JsonPropertyName("errmsg")]
    public string ErrorMessage { get; set; }

    [JsonIgnore]
    public bool IsSuccess => string.IsNullOrEmpty(ErrorCode) && !string.IsNullOrEmpty(AccessToken);
}

public class WeChatUserInfo
{
    [JsonPropertyName("openid")]
    public string OpenId { get; set; }

    [JsonPropertyName("nickname")]
    public string NickName { get; set; }

    [JsonPropertyName("sex")]
    public int Sex { get; set; }

    [JsonPropertyName("province")]
    public string Province { get; set; }

    [JsonPropertyName("city")]
    public string City { get; set; }

    [JsonPropertyName("country")]
    public string Country { get; set; }

    [JsonPropertyName("headimgurl")]
    public string HeadImgUrl { get; set; }

    [JsonPropertyName("unionid")]
    public string UnionId { get; set; }

    [JsonPropertyName("scope")]
    public string Scope { get; set; }
}

public class UserSession
{
    public string SessionId { get; set; }
    public string OpenId { get; set; }
    public WeChatUserInfo UserInfo { get; set; }
    public string AccessToken { get; set; }
    public string RefreshToken { get; set; }
    public DateTime CreatedAt { get; set; }
    public DateTime LastAccessedAt { get; set; }
    public DateTime ExpiresAt { get; set; }

    [JsonIgnore]
    public bool IsExpired => DateTime.UtcNow >= ExpiresAt;
}

public class StateInfo
{
    public string RedirectUri { get; set; }
    public string ReturnUrl { get; set; }
    public string OriginalHost { get; set; }
    public string OriginalScheme { get; set; }
    public string UserAgent { get; set; }
    public DateTime CreatedAt { get; set; }
    public bool IsSilentAuth { get; set; }
}

public class AuthProcessResult
{
    public bool Success { get; set; }
    public UserSession Session { get; set; }
    public string ReturnUrl { get; set; }
    public WeChatUserInfo UserInfo { get; set; }
}